package com.dyp.demo.config;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.Arrays;
import java.util.Map;

@Component
public class CustomInfoContributor implements InfoContributor {
    @Override
    public void contribute(Info.Builder builder) {
        builder.withDetail("runtime",  System.getProperty("java.version"))
                .withDetail("activeProfiles", Arrays.asList("dev",  "actuator"))
                .withDetail("dynamic", fetchFromDatabase())
                .withDetail("customData", Map.of("timestamp",  Instant.now()));
    }

    private Map<String, String> fetchFromDatabase() {
        // 模拟从数据库查询
        return Map.of("dbStatus",  "healthy");
    }
}